//
//  ZDDismissAnimation.m
//  OCSinaWeiBo
//
//  Created by Apple on 15/11/11.
//  Copyright © 2015年 itcast. All rights reserved.
//

#import "ZDDismissAnimation.h"

@implementation ZDDismissAnimation

//指定动画时间
- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext
{
    return 0.25;
}


//指定动画
- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext
{
    //获取即将dismiss的视图
    UIView *fromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
    
    //添加到容器视图中 ———— 如果是自己定义转场动画，需要自己手动添加视图到容器视图中
    [[transitionContext containerView] addSubview:fromView];
    
    //执行动画
    [UIView animateWithDuration:[self transitionDuration:nil] delay:0 usingSpringWithDamping:0.6 initialSpringVelocity:2 options:0 animations:^{
        
        fromView.transform = CGAffineTransformMakeScale(1.0, 0.01);
        
    } completion:^(BOOL finished) {
        
        //动画执行完后，必须调用如下方法 告诉系统转场动画执行完成 否则系统任务转场动画没有完成  不能交互
        [transitionContext completeTransition:YES];
    }];
}


@end
